﻿// Author: Iulian Lita
// Project: DatabaseModule
// Path: C:\Users\Tym\Documents\Visual Studio 2008\Projects\Library\DatabaseModule
// Creation date: 1/12/2009 4:03 AM
// Last modified: 1/14/2009 8:18 AM

#region Using directives
using Error;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Linq;
using System.Text;
#endregion

namespace DatabaseModule
{
    /// <summary>
    /// Database work
    /// </summary>
    public class DatabaseWork : IDisposable
    {
        private SqlConnection _conexiune;

        /// <summary>
        /// Create database work
        /// </summary>
        public DatabaseWork()
        {
            _conexiune = new SqlConnection(@"Data Source=TYM-PC\SQLEXPRESS;Initial Catalog=library;Integrated Security=True");
            OpenConnection();
        } // DatabaseWork()

        protected void OpenConnection()
        {
            try
            {
                _conexiune.Open();                
            }
            catch (Exception)
            {
                ErrorManagement.ManageException(new Exception("Realizarea conexiunii cu baza de date esuata"));
            }
        } // OpenConnection()

        protected void CloseConnection()
        {
            try
            {
                _conexiune.Close();                
            }
            catch (Exception)
            {
                ErrorManagement.ManageException(new Exception("Realizarea deconectarii de la baza de date esuata"));
            }
        } // CloseConnection()

        /// <summary>
        /// Login
        /// </summary>
        /// <param name="username">Username</param>
        /// <param name="password">Password</param>
        public string Login(string username, string password)
        {
            SqlDataReader myReader = null;
            string loginResult = "";
            try
            {

                SqlCommand myCommand = new SqlCommand("SELECT idUtilizator, penalizat, idTipUtilizator, activ, nume from dbo.utilizator where username='" + username + "' and password='" + password + "'", _conexiune);
                myReader = myCommand.ExecuteReader();
                if (!myReader.HasRows)
                    return null;
                else
                {
                    myReader.Read();
                    for (int i = 0; i < 5; i++)
                    {
                        loginResult += myReader[i];
                        if (i != 4)
                        {
                            loginResult += "*";
                        }
                    }
                } // else
            } // try
            catch (Exception e)
            {
                ErrorManagement.ManageException(e);
            }
            finally
            {
                myReader.Close();
            }
            return loginResult;
        } // Login(username, password)

        /// <summary>
        /// Add user
        /// </summary>
        /// <param name="lastName">Last name</param>
        /// <param name="firstName">First name</param>
        /// <param name="cnp">Cnp</param>
        /// <param name="email">Email</param>
        /// <param name="username">Username</param>
        /// <param name="password">Password</param>
        /// <param name="idUserType">Id user type</param>
        /// <param name="registerDate">Register date</param>
        public void AddUser(string lastName, string firstName, string cnp, string email, string username, string password, int idUserType, string registerDate)
        {
            SqlDataReader myReader = null;
            try
            {
                SqlCommand myCommand = new SqlCommand("INSERT INTO dbo.utilizator (nume, prenume, cnp, email, username, password, penalizat, idTipUtilizator, activ) " + "Values ('" + lastName + "','" + firstName + "','" + cnp + "','" + email + "','" + username + "','" + password + "',0," + idUserType + ",1)", _conexiune);
                myReader = myCommand.ExecuteReader();
                if (myReader.RecordsAffected == 0)
                    Debug.WriteLine("Insert failed.");
                AddUserHistory(GetUserId(username), registerDate);
            }
            catch (Exception e)
            {
                //Console.WriteLine(e.Message);
                ErrorManagement.ManageException(new Exception("Failed to add user: " + username));
            }
            finally
            {
                myReader.Close();
            }
        } // AddUser(lastName, firstName, cnp)        

        /// <summary>
        /// Get user id
        /// </summary>
        /// <param name="username">Username</param>
        public int GetUserId(string username)
        {
            SqlDataReader myReader = null;
            int userId = 0;
            try
            {
                SqlCommand myCommand = new SqlCommand("SELECT idUtilizator from dbo.utilizator where username='" + username + "'", _conexiune);
                myReader = myCommand.ExecuteReader();
                myReader.Read();
                userId = (int)myReader[0];
            }
            catch (Exception e)
            {
                ErrorManagement.ManageException(e);
            }
            finally
            {
                myReader.Close();
            }
            return userId;
        } // GetUserId(username)

        /// <summary>
        /// Get user last name
        /// </summary>
        /// <param name="userId">User id</param>
        public string GetUserLastName(int userId)
        {
            SqlDataReader myReader = null;
            string userLastName = "";
            try
            {
                SqlCommand myCommand = new SqlCommand("SELECT nume from dbo.utilizator where idUtilizator=" + userId, _conexiune);
                myReader = myCommand.ExecuteReader();
                myReader.Read();
                userLastName = (string)myReader[0];
            }
            catch (Exception e)
            {
                ErrorManagement.ManageException(e);
            }
            finally
            {
                myReader.Close();
            }
            return userLastName;
        } // GetUserLastName(userId)

        /// <summary>
        /// Get user first name
        /// </summary>
        /// <param name="userId">User id</param>
        public string GetUserFirstName(int userId)
        {
            SqlDataReader myReader = null;
            string userFirstName = "";
            try
            {
                SqlCommand myCommand = new SqlCommand("SELECT prenume from dbo.utilizator where idUtilizator=" + userId, _conexiune);
                myReader = myCommand.ExecuteReader();
                myReader.Read();
                userFirstName = (string)myReader[0];
            }
            catch (Exception e)
            {
                ErrorManagement.ManageException(e);
            }
            finally
            {
                myReader.Close();
            }
            return userFirstName;
        } // GetUserFirstName(userId)

        /// <summary>
        /// Get user cnp
        /// </summary>
        /// <param name="userId">User id</param>
        public string GetUserCnp(int userId)
        {
            SqlDataReader myReader = null;
            string userCnp = "";
            try
            {
                SqlCommand myCommand = new SqlCommand("SELECT cnp from dbo.utilizator where idUtilizator=" + userId, _conexiune);
                myReader = myCommand.ExecuteReader();
                myReader.Read();
                userCnp = (string)myReader[0];
            }
            catch (Exception e)
            {
                ErrorManagement.ManageException(e);
            }
            finally
            {
                myReader.Close();
            }
            return userCnp;
        } // GetUserCnp(userId)

        /// <summary>
        /// Get user email
        /// </summary>
        /// <param name="userId">User id</param>
        public string GetUserEmail(int userId)
        {
            SqlDataReader myReader = null;
            string userEmail = "";
            try
            {
                SqlCommand myCommand = new SqlCommand("SELECT email from dbo.utilizator where idUtilizator=" + userId, _conexiune);
                myReader = myCommand.ExecuteReader();
                myReader.Read();
                userEmail = (string)myReader[0];
            }
            catch (Exception e)
            {
                ErrorManagement.ManageException(e);
            }
            finally
            {
                myReader.Close();
            }
            return userEmail;
        } // GetUserEmail(userId)

        /// <summary>
        /// Get username
        /// </summary>
        /// <param name="userId">User id</param>
        public string GetUsername(int userId)
        {
            SqlDataReader myReader = null;
            string username = "";
            try
            {
                SqlCommand myCommand = new SqlCommand("SELECT username from dbo.utilizator where idUtilizator=" + userId, _conexiune);
                myReader = myCommand.ExecuteReader();
                myReader.Read();
                username = (string)myReader[0];
            }
            catch (Exception e)
            {
                ErrorManagement.ManageException(e);
            }
            finally
            {
                myReader.Close();
            }
            return username;
        } // GetUsername(userId)

        /// <summary>
        /// Get user password
        /// </summary>
        /// <param name="userId">User id</param>
        public string GetUserPassword(int userId)
        {
            SqlDataReader myReader = null;
            string password = "";
            try
            {
                SqlCommand myCommand = new SqlCommand("SELECT password from dbo.utilizator where idUtilizator=" + userId, _conexiune);
                myReader = myCommand.ExecuteReader();
                myReader.Read();
                password = (string)myReader[0];
            }
            catch (Exception e)
            {
                ErrorManagement.ManageException(e);
            }
            finally
            {
                myReader.Close();
            }
            return password;
        } // GetUserPassword(userId)

        /// <summary>
        /// Get user penalized
        /// </summary>
        /// <param name="userId">User id</param>
        public int GetUserPenalized(int userId)
        {
            SqlDataReader myReader = null;
            int penalized = 0;
            try
            {
                SqlCommand myCommand = new SqlCommand("SELECT penalizat from dbo.utilizator where idUtilizator=" + userId, _conexiune);
                myReader = myCommand.ExecuteReader();
                myReader.Read();
                penalized = (int)myReader[0];
            }
            catch (Exception e)
            {
                ErrorManagement.ManageException(e);
            }
            finally
            {
                myReader.Close();
            }
            return penalized;
        } // GetUserPenalized(userId)

        /// <summary>
        /// Get user type ip
        /// </summary>
        /// <param name="userId">User id</param>
        public int GetUserTypeIp(int userId)
        {
            SqlDataReader myReader = null;
            int userTypeIp = 0;
            try
            {
                SqlCommand myCommand = new SqlCommand("SELECT idTipUtilizator from dbo.utilizator where idUtilizator=" + userId, _conexiune);
                myReader = myCommand.ExecuteReader();
                myReader.Read();
                userTypeIp = (int)myReader[0];
            }
            catch (Exception e)
            {
                ErrorManagement.ManageException(e);
            }
            finally
            {
                myReader.Close();
            }
            return userTypeIp;
        } // GetUserTypeIp(userId)

        /// <summary>
        /// Get user active
        /// </summary>
        /// <param name="userId">User id</param>
        public int GetUserActive(int userId)
        {
            SqlDataReader myReader = null;
            int active = 0;
            try
            {
                SqlCommand myCommand = new SqlCommand("SELECT activ from dbo.utilizator where idUtilizator=" + userId, _conexiune);
                myReader = myCommand.ExecuteReader();
                myReader.Read();
                active = (int)myReader[0];
            }
            catch (Exception e)
            {
                ErrorManagement.ManageException(e);
            }
            finally
            {
                myReader.Close();
            }
            return active;
        } // GetUserActive(userId)

        /// <summary>
        /// Update user last name
        /// </summary>
        /// <param name="lastName">Last name</param>
        /// <param name="username">Username</param>
        public void UpdateUserLastName(string lastName, string username)
        {
            SqlDataReader myReader = null;
            try
            {
                SqlCommand myCommand = new SqlCommand("UPDATE dbo.utilizator set nume = '" + lastName + "' where username = '" + username + "'", _conexiune);
                myReader = myCommand.ExecuteReader();
                if (myReader.RecordsAffected == 0)
                    Debug.WriteLine("Update failed.");

            }
            catch (Exception e)
            {
                //Console.WriteLine(e.Message);
                ErrorManagement.ManageException(new Exception("Updatarea bazei de date esuata"));
            }
            finally
            {
                myReader.Close();
            }
        } // UpdateUserLastName(lastName, username)

        /// <summary>
        /// Update user first name
        /// </summary>
        /// <param name="firstName">First name</param>
        /// <param name="username">Username</param>
        public void UpdateUserFirstName(string firstName, string username)
        {
            SqlDataReader myReader = null;
            try
            {
                SqlCommand myCommand = new SqlCommand("UPDATE dbo.utilizator set prenume = '" + firstName + "' where username = '" + username + "'", _conexiune);
                myReader = myCommand.ExecuteReader();
                if (myReader.RecordsAffected == 0)
                    Debug.WriteLine("Update failed.");

            }
            catch (Exception e)
            {
                //Console.WriteLine(e.Message);
                ErrorManagement.ManageException(new Exception("Updatarea bazei de date esuata"));
            }
            finally
            {
                myReader.Close();
            }
        } // UpdateUserFirstName(firstName, username)

        /// <summary>
        /// Update user email
        /// </summary>
        /// <param name="email">Email</param>
        /// <param name="username">Username</param>
        public void UpdateUserEmail(string email, string username)
        {
            SqlDataReader myReader = null;
            try
            {
                SqlCommand myCommand = new SqlCommand("UPDATE dbo.utilizator set email = '" + email + "' where username = '" + username + "'", _conexiune);
                myReader = myCommand.ExecuteReader();
                if (myReader.RecordsAffected == 0)
                    Debug.WriteLine("Update failed.");

            }
            catch (Exception e)
            {
                //Console.WriteLine(e.Message);
                ErrorManagement.ManageException(new Exception("Updatarea bazei de date esuata"));
            }
            finally
            {
                myReader.Close();
            }
        } // UpdateUserEmail(email, username)

        /// <summary>
        /// Update user password
        /// </summary>
        /// <param name="password">Password</param>
        /// <param name="username">Username</param>
        public void UpdateUserPassword(string password, string username)
        {
            SqlDataReader myReader = null;
            try
            {
                SqlCommand myCommand = new SqlCommand("UPDATE dbo.utilizator set password = '" + password + "' where username = '" + username + "'", _conexiune);
                myReader = myCommand.ExecuteReader();
                if (myReader.RecordsAffected == 0)
                    Debug.WriteLine("Update failed.");

            }
            catch (Exception e)
            {
                //Console.WriteLine(e.Message);
                ErrorManagement.ManageException(new Exception("Updatarea bazei de date esuata"));
            }
            finally
            {
                myReader.Close();
            }
        } // UpdateUserPassword(password, username)

        /// <summary>
        /// Update user penalized
        /// </summary>
        /// <param name="penalized">Penalized</param>
        /// <param name="username">Username</param>
        public void UpdateUserPenalized(int penalized, int idUser)
        {
            SqlDataReader myReader = null;
            try
            {
                SqlCommand myCommand = new SqlCommand("UPDATE dbo.utilizator set penalizat = " + penalized + " where idUtilizator = " + idUser, _conexiune);
                myReader = myCommand.ExecuteReader();
                if (myReader.RecordsAffected == 0)
                    Debug.WriteLine("Update failed.");

            }
            catch (Exception)
            {
                //Console.WriteLine(e.Message);
                //ErrorManagement.ManageException(new Exception("Updatarea bazei de date esuata"));
                myReader.Close();
                throw new Exception("Updatarea bazei de date esuata");
            }
            finally
            {
                myReader.Close();
            }
        } // UpdateUserPenalized(penalized, username)

        /// <summary>
        /// Update user active
        /// </summary>
        /// <param name="active">Active</param>
        /// <param name="username">Username</param>
        public void UpdateUserActive(int active, int idUser)
        {
            SqlDataReader myReader = null;
            try
            {
                SqlCommand myCommand = new SqlCommand("UPDATE dbo.utilizator set activ = " + active + " where idUtilizator = " + idUser , _conexiune);
                myReader = myCommand.ExecuteReader();
                if (myReader.RecordsAffected == 0)
                    Debug.WriteLine("Update failed.");

            }
            catch (Exception e)
            {
                //Console.WriteLine(e.Message);
                ErrorManagement.ManageException(new Exception("Updatarea bazei de date esuata"));
            }
            finally
            {
                myReader.Close();
            }
        } // UpdateUserActive(active, username)

        /// <summary>
        /// Add product details
        /// </summary>
        /// <param name="title">Title</param>
        /// <param name="producer">Producer</param>
        /// <param name="idProductType">Id product type</param>
        /// <param name="idDomain">Id domain</param>
        /// <param name="year">Year</param>
        /// <param name="description">Description</param>
        /// <param name="image">Image</param>
        public void AddProductDetails(string title, string producer, int idProductType, int idDomain, string year, string description, string image, string author)
        {
            SqlDataReader myReader = null;
            try
            {
                SqlCommand myCommand = new SqlCommand("INSERT INTO dbo.detaliiProdus (titlu, producator, idTipProdus, idDomeniu, anAparitie, descriere, imagine, autor) " + "Values ('" + title + "','" + producer + "'," + idProductType + "," + idDomain + ",'" + year + "','" + description + "','" + image + "', '"+author+"')", _conexiune);
                myReader = myCommand.ExecuteReader();
                if (myReader.RecordsAffected == 0)
                    Debug.WriteLine("Insert failed.");

            }
            catch (Exception e)
            {
                //Console.WriteLine(e.Message);
                ErrorManagement.ManageException(new Exception("Failed to add product details"));
            }
            finally
            {
                myReader.Close();
            }
        } // AddProductDetails(title, producer, idProductType)

        /// <summary>
        /// Add login
        /// </summary>
        /// <param name="userId">User id</param>
        /// <param name="loginDate">Login date</param>
        public void AddLogin(int userId, string loginDate)
        {
            SqlDataReader myReader = null;
            try
            {
                SqlCommand myCommand = new SqlCommand("INSERT INTO dbo.logare (idUtilizator, dataLogare) " + "Values (" + userId + ",'" + loginDate + "')", _conexiune);
                myReader = myCommand.ExecuteReader();
                if (myReader.RecordsAffected == 0)
                    Debug.WriteLine("Insert failed.");

            }
            catch (Exception e)
            {
                //Console.WriteLine(e.Message);
                ErrorManagement.ManageException(new Exception("Failed to add login details"));
            }
            finally
            {
                myReader.Close();
            }
        } // AddLogin(userId, loginDate)

        /// <summary>
        /// Add user history
        /// </summary>
        /// <param name="userId">User id</param>
        /// <param name="registerDate">Register date</param>
        public void AddUserHistory(int userId, string registerDate)
        {
            SqlDataReader myReader = null;
            try
            {
                SqlCommand myCommand = new SqlCommand("INSERT INTO dbo.istoricUtilizator (idUtilizator, dataInregistrare) " + "Values (" + userId + ",'" + registerDate + "')", _conexiune);
                myReader = myCommand.ExecuteReader();
                if (myReader.RecordsAffected == 0)
                    Debug.WriteLine("Insert failed.");

            }
            catch (Exception e)
            {
                //Console.WriteLine(e.Message);
                ErrorManagement.ManageException(new Exception("Failed to add istoric details"));
            }
            finally
            {
                myReader.Close();
            }
        } // AddUserHistory(userId, registerDate)

        /// <summary>
        /// Delete user
        /// </summary>
        /// <param name="userId">User id</param>
        /// <param name="deleteDate">Delete date</param>
        /// <param name="username">Username</param>
        public void DeleteUser(int userId, string deleteDate, string username)
        {
            SqlDataReader myReader = null;
            try
            {
                SqlCommand myCommand = new SqlCommand("UPDATE dbo.istoricUtilizator set dataStergere = '" + deleteDate + "' where idUtilizator = " + userId, _conexiune);
                myReader = myCommand.ExecuteReader();
                if (myReader.RecordsAffected == 0)
                    Debug.WriteLine("Update failed.");
                UpdateUserActive(0, userId);
            }
            catch (Exception e)
            {
                //Console.WriteLine(e.Message);
                ErrorManagement.ManageException(new Exception("Updatarea bazei de date esuata"));
            }
            finally
            {
                myReader.Close();
            }
        } // DeleteUser(userId, deleteDate, username)

        /// <summary>
        /// Add penalty
        /// </summary>
        /// <param name="userId">User id</param>
        /// <param name="penaltyDate">Penalty date</param>
        /// <param name="reason">Reason</param>
        public void AddPenalty(int userId, string penaltyDate, string reason)
        {
            SqlDataReader myReader = null;
            try
            {
                SqlCommand myCommand = new SqlCommand("INSERT INTO dbo.penalizare (idUtilizator, dataPenalizare, motiv) " + "Values (" + userId + ",'" + penaltyDate + "','" + reason + "')", _conexiune);
                myReader = myCommand.ExecuteReader();
                if (myReader.RecordsAffected == 0)
                    Debug.WriteLine("Insert failed.");
               // UpdateUserPenalized(1, username);
            }
            catch (Exception e)
            {
                //Console.WriteLine(e.Message);
                ErrorManagement.ManageException(new Exception("Failed to add penalty details"));
            }
            finally
            {
                myReader.Close();
            }
        } // AddPenalty(userId, penaltyDate, reason)

        /// <summary>
        /// Remove penalty
        /// </summary>
        /// <param name="userId">User id</param>
        /// <param name="payDate">Pay date</param>
        public void RemovePenalty(int userId, string payDate)
        {
            SqlDataReader myReader = null;
            try
            {
                SqlCommand myCommand = new SqlCommand("UPDATE dbo.penalizare set dataPlata = '" + payDate + "' where idUtilizator = " + userId, _conexiune);
                myReader = myCommand.ExecuteReader();
                if (myReader.RecordsAffected == 0)
                    Debug.WriteLine("Update failed.");
                //UpdateUserPenalized(0, username);
            }
            catch (Exception e)
            {
                //Console.WriteLine(e.Message);
                ErrorManagement.ManageException(new Exception("Updatarea bazei de date esuata"));
            }
            finally
            {
                myReader.Close();
            }
        } // RemovePenalty(userId, payDate)

        /// <summary>
        /// Add item
        /// </summary>
        /// <param name="idProdus">Id produs</param>
        /// <param name="pret">Pret</param>
        public void AddItem(int idProdus, int pret)
        {
            SqlDataReader myReader = null;
            try
            {
                SqlCommand myCommand = new SqlCommand("INSERT INTO dbo.exemplar (idProdus, pret, idStareProdus, ptImprumutat, inStoc) " + "Values (" + idProdus + "," + pret + ", 1, 0, 0)", _conexiune);
                myReader = myCommand.ExecuteReader();
                if (myReader.RecordsAffected == 0)
                    Debug.WriteLine("Insert failed.");

            }
            catch (Exception e)
            {
                //Console.WriteLine(e.Message);
                ErrorManagement.ManageException(new Exception("Failed to add item details"));
            }
            finally
            {
                myReader.Close();
            } 
        } // AddItem(idProdus, pret)

        /// <summary>
        /// Add recomandation
        /// </summary>
        /// <param name="idItem">Id item</param>
        public void AddRecomandation(int idItem) 
        {
            SqlDataReader myReader = null;
            try
            {
                SqlCommand myCommand = new SqlCommand("INSERT INTO dbo.recomandari (id_exemplar) " + "Values (" + idItem + ")", _conexiune);
                myReader = myCommand.ExecuteReader();
                if (myReader.RecordsAffected == 0)
                    Debug.WriteLine("Insert failed.");

            }
            catch (Exception e)
            {
                //Console.WriteLine(e.Message);
                ErrorManagement.ManageException(new Exception("Failed to add item details"));
            }
            finally
            {
                myReader.Close();
            } 
        } // AddRecomandation(i)

        /// <summary>
        /// Add loan
        /// </summary>
        /// <param name="idUser">Id user</param>
        /// <param name="idItem">Id item</param>
        public void AddLoan(int idUser, int idItem)
        {
            SqlDataReader myReader = null;
            try
            {
                SqlCommand myCommand = new SqlCommand("INSERT INTO dbo.imprumut (idUtilizator, idExemplar, dataStart) " + "Values (" + idUser+ ", "+ idItem +", '"+DateTime.Now.ToLocalTime().ToString()+"')", _conexiune);
                myReader = myCommand.ExecuteReader();
                if (myReader.RecordsAffected == 0)
                    Debug.WriteLine("Insert failed.");

            }
            catch (Exception e)
            {
                //Console.WriteLine(e.Message);
                ErrorManagement.ManageException(new Exception("Failed to add item details"));
            }
            finally
            {
                myReader.Close();
            } 
        } // AddLoan(idUser, idItem)

        /// <summary>
        /// Get id item from id product
        /// </summary>
        /// <param name="idProd">Id prod</param>
        public int GetIdItemFromIdProduct(int idProd)
        {
            SqlDataReader myReader = null;
            try
            {
                SqlCommand myCommand = new SqlCommand("SELECT idExemplar from dbo.exemplar where idProdus=" + idProd + " and ptImprumutat = 1", _conexiune);
                myReader = myCommand.ExecuteReader();
                if (myReader.HasRows)
                {
                    myReader.Read();
                    return (int)myReader[0];
                }

            }
            catch (Exception e)
            {
                //Console.WriteLine(e.Message);
                ErrorManagement.ManageException(new Exception("Failed to add item details"));
                return -1;
            }
            finally
            {
                myReader.Close();
            } return -1;  
        } // GetIdItemFromIdProduct(idProd)
        /// <summary>
        /// Update availibility
        /// </summary>
        /// <param name="idItem">Id item</param>
        public void UpdateAvailibility(int idItem)
        {
            SqlDataReader myReader = null;
            try
            {
                SqlCommand myCommand = new SqlCommand("UPDATE dbo.exemplar set ptImprumutat = 0 where idExemplar = "+ idItem, _conexiune);
                myReader = myCommand.ExecuteReader();
                if (myReader.RecordsAffected == 0)
                {
                    Debug.WriteLine("Update ptImprumut failed...");
                }

            }
            catch (Exception e)
            {
                //Console.WriteLine(e.Message);
                ErrorManagement.ManageException(new Exception("Failed to add item details"));
                
            }
            finally
            {
                myReader.Close();
            } 
        } // UpdateAvailibility(idItem)
        #region IDisposable Members

        /// <summary>
        /// Dispose
        /// </summary>
        public void Dispose()
        {
            CloseConnection();
        } // Dispose()

        #endregion
    } // class DatabaseWork
} // namespace DatabaseModule
